package com.xiaohong.seckill.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.seckill.dao.SeckillGoodsMapper;
import com.xiaohong.seckill.pojo.SeckillGoods;
import com.xiaohong.seckill.service.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SeckillGoodsServiceImpl implements SeckillGoodsService {

    @Autowired
    private SeckillGoodsMapper seckillGoodsMapper;


    /**
     * 条件+分页查询SeckillGoods
     * @param seckillGoods 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<SeckillGoods> findPage(SeckillGoods seckillGoods, int page, int size){
        // 构建查询条件
        QueryWrapper<SeckillGoods> queryWrapper = new QueryWrapper<SeckillGoods>(seckillGoods);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return seckillGoodsMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询SeckillGoods
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<SeckillGoods> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return seckillGoodsMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法SeckillGoods
     * @param seckillGoods
     * @return
     */
    @Override
    public List<SeckillGoods> findList(SeckillGoods seckillGoods){
        // 构建查询条件
        QueryWrapper<SeckillGoods> queryWrapper = new QueryWrapper<SeckillGoods>(seckillGoods);
        // 查询数据
        return seckillGoodsMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除SeckillGoods
     * @param id
     */
    @Override
    public void delete(Long id){
        seckillGoodsMapper.deleteById(id);
    }

    /**
     * 根据ID修改SeckillGoods
     * @param seckillGoods
     */
    @Override
    public void update(SeckillGoods seckillGoods){
        seckillGoodsMapper.updateById(seckillGoods);
    }

    /**
     * 增加SeckillGoods
     * @param seckillGoods
     */
    @Override
    public void add(SeckillGoods seckillGoods){
        seckillGoodsMapper.insert(seckillGoods);
    }

    /**
     * 根据ID查询SeckillGoods
     * @param id
     * @return
     */
    @Override
    public SeckillGoods findById(Long id){
        return  seckillGoodsMapper.selectById(id);
    }

    /**
     * 查询全部SeckillGoods数据
     * @return
     */
    @Override
    public List<SeckillGoods> findAll() {
        return seckillGoodsMapper.selectList(null);
    }
}
